﻿$(document).on("pageInit", "#create-timetable-contact", function (e, id, page) {
    $(page).find('[name="StartTime"]').on("click", function (evt) {
        var timePicker = new DateTimePicker.Time({
            lang: 'zh-CN',
            format: 'HH:mm',
            //min: '06:00',
            //max: '20:30',
            minuteStep: 1
        })
        timePicker.on('selected', function (formatTime, now) {
            $(page).find('[name="StartTime"]').val(formatTime);
        });
        timePicker.on('cleared', function () {
            $(page).find('[name="StartTime"]').val("");
        });
    });

    $(page).find('[name="StopTime"]').on("click", function (evt) {
        var timePicker = new DateTimePicker.Time({
            lang: 'zh-CN',
            format: 'HH:mm',
            minuteStep: 1
        })
        timePicker.on('selected', function (formatTime, now) {
            $(page).find('[name="StopTime"]').val(formatTime);
        });
        timePicker.on('cleared', function () {
            $(page).find('[name="StopTime"]').val("");
        });
    });

    $.getJSON("/timetable/GetAllCourceList", {}, function (response) {
        var $CourceId = $(page).find('[name="CourceId"]');
        $CourceId.empty();
        $.each(response, function (rIndex, rItem) {
            $CourceId.append("<option value='" + rItem.Id + "'>" + rItem.CourceName + "</option>");
        });
    });

    $.getJSON("/timetable/GetTeacherList", {}, function (response) {
        var $CourceId = $(page).find('[name="UserId"]');
        $CourceId.empty();
        $.each(response, function (rIndex, rItem) {
            $CourceId.append("<option value='" + rItem.Id + "'>" + rItem.RealName + "</option>");
        });
    });


    $(page).find("[name=save-timetable-contact-form]").on("submit", function (evt) {
        evt.preventDefault();
        $(page).find("[name=save-timetable-contact-form]").ajaxSubmit({
            success: function (response) {
                if (response.indexOf("err:") > -1) {
                    $.toast(response.substr(4));
                    return false;
                }
                history.back();
            }
        });
    });
});